<template>
  <div class="box">
    <h2>子组件 add----{{ count }}</h2>
    从vuex中获取的值:<label>{{ count }}</label>
    <br />
    <button @click="add">值+1</button>
    <button @click="asyncAdd">延时一秒值+1</button>
    <button @click="$store.dispatch('getadd',10000)">延时一秒值1000</button>
    <button @click="asyncAdd">延时一秒值+1</button>

  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'AddItem',
  computed:{
    // 帮我们简写计算属性 所有称为辅助函数
    ...mapState(['count']),
  },
  methods:{
    add(){
      this.$store.commit('incremCount')
    },
    asyncAdd(){
      this.$store.dispatch('asyncIncrem')
    }
  }
}
</script>

<style lang="css" scoped>
.box {
  border: 3px solid #ccc;
  width: 400px;
  padding: 10px;
  margin: 20px;
}
h2 {
  margin-top: 10px;
}
</style>